package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConstant;
import com.itheima.entity.Result;
import com.itheima.service.MemberService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;


@RestController
@RequestMapping("report")
public class ReportController {

    @Reference
    private MemberService memberService;
    @RequestMapping("getMemberReport")
    public Result getMemberReport() {
        try {
            Map map= memberService.getMemberReport();
            return new Result(true, MessageConstant.GET_MEMBER_NUMBER_REPORT_SUCCESS,map);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(true, MessageConstant.GET_MEMBER_NUMBER_REPORT_FAIL);

        }
    }

    //查询一定时间段内的每个月会员数量
    @RequestMapping("getMemberReportByDateRange")
    public Result getSetmealReportByDateRange(@RequestParam("start")String startDate, @RequestParam("end")String endDate){
        try {
            Map map = memberService.getMemberReportByDateRange(startDate,endDate);
            return new Result(true, MessageConstant.GET_MEMBER_NUMBER_REPORT_SUCCESS,map);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.GET_MEMBER_NUMBER_REPORT_FAIL);
        }
    }
    //年龄占比
    @RequestMapping("getMemberReportByAge")
    public Result getMemberReportByAge(){
        try {
            Map map= memberService.getMemberReportByAge();
            return new Result(true, MessageConstant.GET_MEMBER_NUMBER_REPORT_SUCCESS,map);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.GET_MEMBER_NUMBER_REPORT_FAIL);
        }
    }


    /*性别占比*/
    @RequestMapping("getSexReport")
    public Result getSexReport() {
        try {
            Map map = memberService.getSexReport();
            return new Result(true, MessageConstant.GET_MEMBER_NUMBER_REPORT_SUCCESS, map);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.GET_MEMBER_NUMBER_REPORT_FAIL);

        }
    }
}
